/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package myproj;

import brain.MyBrain;
import myjme.JmeCanvas;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeCanvasContext;
import controller.MyController;
import database.create.CreateMyDatabase;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javafx.application.Platform;
import javafx.scene.paint.Color;
import javax.swing.JFrame;
import myfx.jfxpanel.JStatusBarImpl;
import myfx.jfxpanel.MyMenu;
import myfx.jfxpanel.MyTreeContainer;
import myprogramui.comp.page2comp.FXTreeForJME;

/**
 *
 * @author zhoumingrui
 */
public class Main {
    //获取屏幕的宽
    public static int screenWidth=java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;
    //获取屏幕的高
    public static int screenHeight=java.awt.Toolkit.getDefaultToolkit().getScreenSize().height;
    private JFrame frame=new JFrame(java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("矿井注浆孔立体显示"));
    //controller设定
    private MyController controller;
    private MyBrain brain;
    public JFrame getJFrame(){
        return this.frame;
    }
    public MyController getController(){
        return this.controller;
    }
    public MyBrain getBrain(){
        return this.brain;
    }
    public void mainxx(String[] args) throws InterruptedException{
        
        final Starter starter=new Starter();
        final CreateMyDatabase createMyDatabase=new CreateMyDatabase();
        Thread.sleep(2000);
        starter.updateStarter(5, java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("完成数据库创建"));
        final MyTreeContainer fxContainer=new MyTreeContainer(300, screenHeight-140,  Color.WHITESMOKE);
        FXTreeForJME fXTreeForJME=new FXTreeForJME(255, screenHeight-140, Color.WHITESMOKE);
        starter.updateStarter(10, java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("完成TREE控件的建立"));
        final MyMenu fxMenu=new MyMenu(screenWidth, 25,  Color.WHITESMOKE);
        starter.updateStarter(15, java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("完成MENU控件的建立"));
        final JStatusBarImpl myStauts=new JStatusBarImpl(screenWidth, 25);
        starter.updateStarter(20, java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("完成状态栏的建立"));
        myStauts.setSize(screenWidth, 26);
        myStauts.addStatusCell((screenWidth-30)/3);
        myStauts.addStatusCell((screenWidth-30)/3);
        myStauts.addStatusCell((screenWidth-30)/3);
        myStauts.setStatus(0, java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("程序启动成功"));
        myStauts.setStatus(1, java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("当前处于MAIN位置"));
        myStauts.setStatus(2, java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("未处于编辑状态"));
        //jme
        AppSettings settings = new AppSettings(true);
        settings.setWidth(1066);
        settings.setHeight(650);
        starter.updateStarter(25, java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("完成JMEAPPSETTING的建立"));
        final JmeCanvas app = new JmeCanvas();
        app.setPauseOnLostFocus(false);
        app.setSettings(settings);
        app.createCanvas();
        app.startCanvas(true);
        
        starter.updateStarter(35, java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("完成JMECANVAS的导入"));
        JmeCanvasContext context = (JmeCanvasContext) app.getContext();
        Canvas canvas = context.getCanvas();
        canvas.setSize(settings.getWidth(), settings.getHeight());
        //add controller and brain
        controller=new MyController(fXTreeForJME,fxContainer,fxMenu,myStauts,app,canvas);
        starter.updateStarter(45, java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("完成总控制器创建"));
        brain=new MyBrain(fxContainer, fxMenu, myStauts, app, controller);
        starter.updateStarter(55, java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("完成总运算器创建"));
        //jfx
        Thread.sleep(1000);

        
        starter.updateStarter(65, java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("完成总GUI的搭建创建"));
        frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        frame.setSize(screenWidth, screenHeight-50);
        frame.setLayout(new BorderLayout());
        frame.getContentPane().add(fxMenu,BorderLayout.NORTH);
        frame.getContentPane().add(fXTreeForJME,BorderLayout.WEST);
        frame.getContentPane().add(canvas, BorderLayout.CENTER);
        frame.getContentPane().add(myStauts,BorderLayout.SOUTH);
        frame.pack();
        starter.updateStarter(75, java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("界面组装成功"));
        frame.setLocationRelativeTo(null);
        frame.addWindowListener(new WindowListener() {

            public void windowOpened(WindowEvent we) {
                
            }

            public void windowClosing(WindowEvent we) {
                controller.getDco().setVisible(false);
            }

            public void windowClosed(WindowEvent we) {
                
            }

            public void windowIconified(WindowEvent we) {
                
            }

            public void windowDeiconified(WindowEvent we) {
                
            }

            public void windowActivated(WindowEvent we) {
                
            }

            public void windowDeactivated(WindowEvent we) {
                
            }
        });
		/*deal with the loading of the fx*/
        Platform.runLater(new Runnable() {

            public void run() {
                try{
                    starter.updateStarter(85, java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("完成菜单栏与FX控件的延迟显示"));
                    fxContainer.createMyTreeContainer();
                    fxMenu.createMenu();
                    starter.updateStarter(99, java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("完成程序加载"));
                    //frame.setVisible(true);
                    starter.updateStarter(100, java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("完成程序加载"));
//                    new Thread(new StatusHelpThread(controller)).start();
                }catch(Exception e){
                }
            }
        });
        
        
    }
}
